package com.study.controller;

import com.study.exception.MyException;
import com.study.pojo.common.Result;
import com.study.pojo.dto.Test;
import com.study.pojo.dto.User;
import com.study.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SearchController {
    @Autowired
    private UserService userService;

    @RequestMapping("/all/user")
    public Result<?> getList() {
        List<User> users = userService.getUsers();

        return Result.success(users);
    }

    @PostMapping("/test")
    public Test insert(@RequestBody @Validated Test test){
        System.out.println(test);
        try {
            int i = 1 / 0;
        }catch (Exception e){
            throw new MyException("烦死了");
        }
        return test;
    }


}
